# 用户模型
from .base import BaseModel
from .database import db
from datetime import datetime

class User(BaseModel):
    __tablename__ = 'users'

    id = db.Column(db.Integer, primary_key=True, autoincrement=True, comment='用户ID')
    name = db.Column(db.String(50), nullable=False, comment='姓名')
    gender = db.Column(db.SmallInteger, default=0, comment='性别（0-未知，1-男，2-女，3-其他）')
    role = db.Column(db.SmallInteger, default=0, comment='身份标识（0-用户，1-管理员）')
    age = db.Column(db.SmallInteger, comment='年龄')
    nickname = db.Column(db.String(50), unique=True, comment='昵称')
    password = db.Column(db.String(255), nullable=False, comment='密码（建议存储加密后的值）')
    profile_code = db.Column(db.String(255), comment='个人码（图片路径或唯一标识）')
    head = db.Column(db.String(255), comment='头像（图片路径或URL）')
    # created_at和updated_at从BaseModel继承
    # 移除is_deleted字段，因为DDL中没有
    created_at = db.Column(db.DateTime, default=datetime.now, comment='创建时间')
    updated_at = db.Column(db.DateTime, default=datetime.now, onupdate=datetime.now, comment='更新时间')
    is_deleted = None

    # 重写to_dict方法，排除is_deleted字段
    def to_dict(self):
        result = super().to_dict()
        result.pop('is_deleted', None)
        return result

    def __repr__(self):
        return f'<User {self.name}>'